/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mvp.levelup.hashs.set;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import mvp.levelup.hashs.model.Account;

/**
 *
 * @author WORKSPOT2
 */
public class HashSetTest
{
    public static void main(String args[])
    {
        HashSet<String> strs = new HashSet<String>();
        strs.add("1");
        strs.add("2");
        strs.add("3");
        strs.add("4");
        strs.add("5");
        strs.add("6");
        strs.add("7");
        strs.add("8");
//        Iterator<String> iter = strs.iterator();
//        while(iter.hasNext())
//        {
//            System.out.println(iter.next());
//        }
        
        HashSet<Account> accounts = new HashSet<Account>();
        accounts.add(new Account(34, 6789));
        accounts.add(new Account(89, 4556));
        accounts.add(new Account(150, 3332));
        accounts.add(new Account(34, 73723));
//        showSet(accounts);
        accounts.remove(new Account(34, -1));
        accounts.add(new Account(34, 73723));
//        showCollection(accounts);
        exampleWithList();
    }
    
    private static void exampleWithList()
    {
        List<Account> accounts = new ArrayList<Account>();
        accounts.add(new Account(1, 4552));
        accounts.add(new Account(2, 55334));
        accounts.add(new Account(3, 3323));
        accounts.add(new Account(4, 55233));
        accounts.add(new Account(5, 3445));
        accounts.add(new Account(6, 7745));
        accounts.add(new Account(3, 33455));
        accounts.add(new Account(4, 99988));
        showCollection(accounts);
        HashSet<Account> uniqueAccounts = new HashSet<Account>(accounts);
        System.out.println("==========");
        showCollection(uniqueAccounts);
    }
    
    
    
    private static void showCollection(Collection<Account> accounts)
    {
        Iterator<Account> iterAcc = accounts.iterator();
        while(iterAcc.hasNext())
        {
            System.out.println(iterAcc.next());
        }
    }
}
